www.gusucode.com > DB-Libray 操作SQLServer编程的VC++ 一例-源码程序 > DB-Libray 操作SQLServer编程的VC++ 一例-源码程序\code\PhManage\SaleRecordMDlg.cpp

    //Download by http://www.NewXing.com
// SaleRecordMDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PhysicM.h"
#include "SaleRecordMDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSaleRecordMDlg dialog


CSaleRecordMDlg::CSaleRecordMDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSaleRecordMDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSaleRecordMDlg)
	m_end_date = _T("");
	m_start_date = _T("");
	//}}AFX_DATA_INIT
}


void CSaleRecordMDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSaleRecordMDlg)
	DDX_Control(pDX, IDC_LIST_RECORD, m_List);
	DDX_Control(pDX, IDC_COMB, m_HospitalComb);
	DDX_Text(pDX, IDC_ENDT, m_end_date);
	DDX_Text(pDX, IDC_STDT, m_start_date);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSaleRecordMDlg, CDialog)
	//{{AFX_MSG_MAP(CSaleRecordMDlg)
	ON_BN_CLICKED(IDC_DELBTN, OnDelbtn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSaleRecordMDlg message handlers

void CSaleRecordMDlg::init()
{
	char *head[]={"序号","医   生","药品名称","数  量 ","临床费","应付金额(元)","折扣费用","实付金额","日期","ID",NULL};//,"备   注"};
		m_List.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	char **p=head;
	int i=0;
	while(*p != NULL)
	{
		m_List.InsertColumn(i,(LPCTSTR)*p,(i>=2) ? LVCFMT_RIGHT : LVCFMT_LEFT,(i>=1) ? 90 : 50);
		p++;
		i++;
	}
	ImageList=new CImageList();
	ImageList->Create(16,16,TRUE | ILC_COLOR32,2,0);
	ImageList->Add(AfxGetApp()->LoadIcon(IDI_ICONUSER));
	ImageList->Add(AfxGetApp()->LoadIcon(IDR_MENUVIEW_TMPL));
	m_List.SetImageList(ImageList,LVSIL_SMALL);// LVSIL_NORMAL);
	DBLibrary DB(((CPhysicMApp *)AfxGetApp())->DBSession);
	m_HospitalComb.ResetContent();
	try
	{
		DB.Open("Select hospital_id hid,hospital_name hn from hospital order by hospital_id");
		char tmp[200];
		
		while(!DB.isEof())
		{
			memset(tmp,0,200);
			sprintf(tmp,"[%03d]",DB.GetValue("hid"));
			DB.GetValue("hn",tmp+5);
			m_HospitalComb.AddString((LPCTSTR)tmp);
			DB.Next();
		}
	}
	catch(DBErr &err)
	{
		char *str;
		int code;
		err.GetLastErr(code,&str);
		((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr(str,code);
	}
	catch(...)
	{
		((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("unknow error !(-1)");
	}
}

BOOL CSaleRecordMDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	if (ImageList) 
		delete ImageList;
	return CDialog::DestroyWindow();
}

BOOL CSaleRecordMDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	init();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSaleRecordMDlg::OnOK() 
{
	// TODO: Add extra validation here
	m_List.DeleteAllItems();
	UpdateData();
	CString m_hpid;
	m_HospitalComb.GetWindowText(m_hpid);
	try{
		if (m_start_date.IsEmpty())
			throw "请输入开始日期";
		if(m_end_date.IsEmpty())
			throw "请输入结束日期";
		if(m_hpid.IsEmpty())
			throw "请选择医院";

		DBLibrary DB( ((CPhysicMApp *)AfxGetApp())->DBSession);
		DB.Open("select b.sale_id sid, a.doctor_name dname,c.physic_name pname,b.physic_num num ,"
			"b.doctor_rate, (b.doctor_rate * b.physic_num) sum_fee, b.sub_fee,b.real_fee,b.sale_date "
			" from doctor a, sale_number b,physic c "
			" where b.sale_date between '%s' and '%s' and b.hospital_id = %s "
			" and b.doctor_id=a.doctor_id and b.physic_id=c.physic_id "
			" order by b.sale_id ",m_start_date,m_end_date,m_hpid.Mid(1,3));
		int i=0;
		char tmp[10][50];
		double val=0.0;
		//{"序号","医   生","药品名称","数  量 ","临床费","应付金额(元)","折扣费用","实付金额","日期","ID",NULL};//,"备   注"};
		while(!DB.isEof())
		{
			memset(tmp,0,sizeof(char)*10*50);
			sprintf(tmp[0],"%03d",i+1);
			DB.GetValue("dname",tmp[1]);
			DB.GetValue("pname",tmp[2]);
			DB.GetValue("num",&val);
			sprintf(tmp[3],"%.2f",val);
			DB.GetValue("doctor_rate",&val);
			sprintf(tmp[4],"%.2f",val);
			DB.GetValue("sum_fee",&val);
			sprintf(tmp[5],"%.2f",val);
			DB.GetValue("sub_Fee",&val);
			sprintf(tmp[6],"%.2f",val);
			DB.GetValue("real_fee",&val);
			sprintf(tmp[7],"%.2f",val);
			DB.GetValue("sale_date",tmp[8]);
			sprintf(tmp[9],"%04d",DB.GetValue("sid"));
			
			m_List.InsertItem(i,(LPCTSTR)tmp[0],0);
			for(int j=1;j<10;j++)
				m_List.SetItemText(i,j,(LPCTSTR)tmp[j]);
			i++;
			DB.Next();
		}

	}
	catch(DBErr &err)
	{
		char *str;
		int code;
		err.GetLastErr(code,&str);
		((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr(str,code);
	}
	catch(char *err)
	{
		((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr(err);
	}
	catch(...)
	{
		((CPhysicMApp *)AfxGetApp())->pMainFrm->AddErr("unknow error !(-1)");
	}

}

void CSaleRecordMDlg::OnDelbtn() 
{
   ((CPhysicMApp *)AfxGetApp())	->Delete("sale_number","sale_id",&m_List,9);
}